var t = db.transactions.findOne({status:"pending"});
if (t){
	db.accounts.update({name:t.source, pending:{$ne:t._id}}, {$inc: {balance:-t.value}, $push: {pending: t._id}});
	db.accounts.update({name:t.destination, pending:{$ne:t._id}}, {$inc: {balance:t.value}, $push: {pending: t._id}});
	db.transactions.update({_id:t._id}, {status:"commited"});
	db.accounts.update({name:t.source}, {$pull: {pending:t._id}});
	db.accounts.update({name:t.destination}, {$pull: {pending:t._id}});
	db.transactions.update({_id:t._id}, {status:"done"});
}


